#! /bin/bash
#SQOOP_HOME=/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/bin/sqoop
export LANG=zh_CN.UTF-8
SQOOP_HOME=/usr/bin/sqoop

if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

echo '========================================'
echo '==============开始全量导入==============='
echo '========================================'

# 全量
echo '--------------tbh_class_time_table--------------'
sqoop import \
--connect jdbc:mysql://hadoop01:3306/teach \
--username root \
--password 123456 \
--query "select id, class_id, morning_template_id, morning_begin_time, morning_end_time, afternoon_template_id, afternoon_begin_time, afternoon_end_time, evening_template_id, evening_begin_time, evening_end_time, use_begin_date, use_end_date, create_time, create_person, remark from teach.tbh_class_time_table where \$CONDITIONS" \
--hcatalog-database db_ods \
--hcatalog-table tbh_class_time_table \
--fields-terminated-by  '\t' \
-m 1

wait


echo '--------------course_table_upload_detail--------------'
sqoop import \
--connect jdbc:mysql://hadoop01:3306/teach \
--username root \
--password 123456 \
--query "select id, base_id, class_id, class_date, content, teacher_id, teacher_name, job_number, classroom_id, classroom_name, is_outline, class_mode, is_stage_exam, is_pay, tutor_teacher_id, tutor_teacher_name, tutor_job_number, is_subsidy, answer_teacher_id, answer_teacher_name, answer_job_number, remark, create_time from teach.course_table_upload_detail where \$CONDITIONS" \
--hcatalog-database db_ods \
--hcatalog-table course_table_upload_detail \
--fields-terminated-by  '\t' \
-m 1
wait


# 增量

echo '--------------class_studying_student_count--------------'
sqoop import \
--connect jdbc:mysql://hadoop01:3306/teach \
--username root \
--password 123456 \
--query "select id, school_id, subject_id, class_id, studying_student_count, studying_date, '${TD_DATE}' as dt from teach.class_studying_student_count where \$CONDITIONS" \
--hcatalog-database db_ods \
--hcatalog-table class_studying_student_count \
--fields-terminated-by  '\t' \
-m 1
wait

echo '--------------student_leave_apply--------------'
sqoop import \
--connect jdbc:mysql://hadoop01:3306/teach \
--username root \
--password 123456 \
--query "select id, class_id, student_id, audit_state, audit_person, audit_time, audit_remark, leave_type, leave_reason, begin_time, begin_time_type, end_time, end_time_type, days, cancel_state, cancel_time, old_leave_id, leave_remark, valid_state, create_time, '${TD_DATE}' as dt from teach.student_leave_apply where \$CONDITIONS" \
--hcatalog-database db_ods \
--hcatalog-table student_leave_apply \
--fields-terminated-by  '\t' \
-m 1
wait

echo '--------------tbh_student_signin_record--------------'
sqoop import \
--connect jdbc:mysql://hadoop01:3306/teach \
--username root \
--password 123456 \
--query "select id, normal_class_flag, time_table_id, class_id, student_id, signin_time, signin_date, inner_flag, signin_type, share_state, inner_ip, '${TD_DATE}' as dt from teach.tbh_student_signin_record where \$CONDITIONS" \
--hcatalog-database db_ods \
--hcatalog-table tbh_student_signin_record \
--fields-terminated-by  '\t' \
-m 1
wait

echo '========================================'
echo '=================success==============='
echo '========================================'